Standard I/O

#include stdio.h>

=The following aliases for some of the below functions are defined.

to #=10pt plus 1 fil&# getcfgetc ungetcfungetc putcfputc getchar()fgetc(stdin) ungetchar(c)fungetc((c),stdin) putchar(c)fputc((c),stdout)

void clearerr(FILE &sstarf#star;fp); Clear error and EOF status of stream fp. (Macro)

int fclose(FILE &sstarf#star;fp); Close the stream fp.

FILE &sstarf#star;fdopen(int fd, const char &sstarf#star;mode); Connect a filepointer to the filedescriptor fd with mode mode.

int feof(FILE &sstarf#star;fp); Test EOF status of stream fp. (Macro)

int ferror(FILE &sstarf#star;fp); Test error status of stream fp. (Macro)

int fflush(FILE &sstarf#star;fp); Write data from internal buffer of stream fp to the file.

int fgetc(FILE &sstarf#star;fp); Get a character from stream fp.

int fgetpos(FILE &sstarf#star;fp, fpos_t &sstarf#star;ptr); Put the current position of the filepointer of stream fp into the address ptr.

char &sstarf#star;fgets(char &sstarf#star;buf, int max, FILE &sstarf#star;fp); Get a string including the NL character from stream fp with max byte into buf.

int fileno(FILE &sstarf#star;fp); Get filedescriptor of stream fp. (Macro)

FILE &sstarf#star;fopen(const char &sstarf#star;fname, const char &sstarf#star;mode); Open file fname with mode mode for stream I/O.

int fputc(int c, FILE &sstarf#star;fp); Write a character c into stream fp.

int fputs(const char &sstarf#star;buf, FILE &sstarf#star;fp); Write the string in buf into stream fp.

size_t fread(void &sstarf#star;buf, size_t sz, size_t no, FILE &sstarf#star;fp); Read no items of size sz from stream fp into buf.

FILE &sstarf#star;freopen(const char &sstarf#star;fname, const char &sstarf#star;mode, FILE &sstarf#star;fp); Reopen fp with file fname and mode mode.

int fseek(FILE &sstarf#star;fp, long pos, int whence); Move the the filepointer from stream fp to position pos relativ to whence.

int fsetpos(FILE &sstarf#star;fp, fpos_t &sstarf#star;ptr); Set the position of the filepointer of stream fp to the value at address ptr.

long ftell(FILE &sstarf#star;fp); Get the current position of the filepointer from stream fp.

int fungetc(int c, FILE &sstarf#star;fp); Push the character c back onto stream fp.

size_t fwrite(const void &sstarf#star;buf, size_t size, size_t no , FILE &sstarf#star;fp); Write no items of size sz from buf into stream fp.

long getl(FILE &sstarf#star;fp); Read a long value from stream fp.

char &sstarf#star;gets(char &sstarf#star;buf); Get a string from stdin> into buf. The NL character is discarded.

short getw(FILE &sstarf#star;fp); Read a short value from stream fp.

int pclose(FILE &sstarf#star;fp); Close the stream created by popen().

void perror(const char &sstarf#star;str); Display error message starting with str depending on errno.

FILE &sstarf#star;popen(const char &sstarf#star;command, const char &sstarf#star;mode); Open a pipe with mode to command. (Faked by temporary files)

int printf(const char &sstarf#star;fmt, …); int fprintf(FILE &sstarf#star;fp, const char &sstarf#star;fmt, …); int sprintf(char &sstarf#star;buf, const char &sstarf#star;fmt, …); int vprintf(const char &sstarf#star;fmt, char &sstarf#star;); int vfprintf(FILE &sstarf#star;fp, const char &sstarf#star;fmt, char &sstarf#star;); int vsprintf(char &sstarf#star;buf, const char &sstarf#star;fmt, char &sstarf#star;); Formated output to either stdout>, fp or buf with fixed or variable number of arguments.

=The following table lists the identifying letters of the fmt string.

scanfprintfMeaning


dd,iDecimal number ooOctal number xx,XHexadecimal number uuUnsigned decimal n. bUnsigned binary int. iAny base num. DDLong Decimal number OOLong Octal number UUUnsigned long decimal XLong Hexadecimal ld,lo,lxld,li,lo,lx,lXLong … number lbUnsigned binary long liAny base num. long hd,ho,hxd,o,x,XShort … number ccCharacter ssString pPointer […]Str. consist. of char. e,f,gfFixed-point number e,f,ge,EFloating-point number le,lf,lgDouble prec. … n. E,F,GDouble prec. … n. Le,Lf,LgLe,LE,LfLong Double … n. g,G,Lg,LGe/E or f - shortest used

long putl(long c, FILE &sstarf#star;fp); Output the long value c into the stream fp.

int puts(const char &sstarf#star;buf); Write the string in buf to stdout> appending a NL character.

short putw(short c, FILE &sstarf#star;fp); Output the short value c into the stream fp.

int remove(const char &sstarf#star;fname); Remove file with name fname.

int rename(const char &sstarf#star;old, const char &sstarf#star;new); Change name of file from old to new.

void rewind(FILE &sstarf#star;fp); Reset the filepointer from stream fp to position 0.

int scanf(const char &sstarf#star;fmt, …); int fscanf(FILE &sstarf#star;fp, const char &sstarf#star;fmt, …); int sscanf(const char &sstarf#star;buf, const char &sstarf#star;fmt, …); Formated input from either stdin>, fp or buf. (For a description of the letters in the fmt string see printf.)

void setbuf(FILE &sstarf#star;fp, char &sstarf#star;buf); Set buffer of stream fp to buf.

The following functions are defined as macros.

int setvbuf(FILE &sstarf#star;fp, char &sstarf#star;buf, int mode, size_t sz); Set buffer of stream fp to buf with size sz and mode mode.

FILE &sstarf#star;tmpfile(void); Create a temporary file. File is deleted on normal termination.

char &sstarf#star;tmpnam(char &sstarf#star;buf); Create a string for a temporary filename.

void _binmode(int bool); Set default open mode to binary (bool = true) or text.